
<?php

/**
 * @author christian monzón
 * @copyright 2011
 */

Class CDrawPageReg
{
    //.enviando nuevos cambios.......................
    
    //agregando nueva variable 
    
    public static $instance2;
    public static $instance;
    
 
    
    function __construct()
    {
      
        
    }
    
    function SimpleDate($label,$id){
    ?>
    <script>
    $(function() {
        $.datepicker.setDefaults($.datepicker.regional['es']);        
        $( "#datepicker" ).datepicker({
			changeMonth: true,
			changeYear: true
		});
	});
	</script>
    
    <p><h3><?php echo $label;?></h3></br> <input type="text" name="<?php echo $id;?>" id="datepicker"/></p>

    <?php
    
    }
    
    
    function SimpleDateFill($label,$id,$f){
    ?>
    <script>
    $(function() {
        $.datepicker.setDefaults($.datepicker.regional['es']);        
        $( "#datepicker" ).datepicker({
			changeMonth: true,
			changeYear: true
		});
	});
	</script>
    
    <p><h3><?php echo $label;?></h3></br> <input type="text" value="<?php echo $f;?>" name="<?php echo $id;?>" id="datepicker"/></p>

    <?php
    
    }
    
    function DateMin($label,$id,$minimo){
    
     ?>
    <script>
    $(function() {
        
       
        $.datepicker.setDefaults($.datepicker.regional['es']);
         
		$( "#datepicker" ).datepicker({minDate:"<?php echo $minimo;?>",
        	defaultDate: "<?php echo $minimo;?>",
        	numberOfMonths: 2
                });
	});
	</script>
    
    <p><?php echo $label;?></br> <input type="text" name="<?php echo $id;?>" id="datepicker"/></p>

    <?php
    
    
        
    }
    
    function DrawSelectReload($table,$campos,$NAME, $id){
        
         $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;
                  
        
        $table2=CModelo::getInstance()->getData($query);
       
       
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?></br>
        <select style="width:400px" name="<?php echo $id;?>" onclick="javascript:reload();" id="<?php echo $id;?>"><option value=""></option>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select></br>       
        </label>

        <div id="reload"></div>
       
    <?php
        
    }
    
    
    function DrawDependence($table,$campos,$NAME,$id,$file){
        ?>
                
        <p align="left">
        <select style="width: 400px" size="1" name="select" onclick="javascript:recargar();" id="opciones">

        <?php 
        CDrawPageReg::getInstance()->DrawSelectNo($table,$campos,$NAME,$id);
        ?>
            
        </select>
    
        <div id="recargado"></div>
        <script language="javascript">
    
    function recargar(){    
       /// Aqui podemos enviarle alguna variable a nuestro script PHP
       //document.write(select);
        var variable_post= document.getElementById("opciones").value;;
       /// Invocamos a nuestro script PHP
        $.post("<?php echo $file;?>", {variable:variable_post}, function(data){
       /// Ponemos la respuesta de nuestro script en el DIV recargado
        $("#recargado").html(data);
    });         
    }
    </script>
        
        <?php
    }
     
     
     function DrawDependenceOption($table,$campos,$NAME,$id,$file){
        ?>
                
        <p align="left">
        <label><?php echo $NAME;?></br>
        <select style="width: 400px" size="1" name="select" onclick="javascript:recargar();" id="opciones"><option value="case">Definir uno nuevo</option>

        <?php 
        CDrawPageReg::getInstance()->DrawSelectNo($table,$campos,$NAME,$id);
        ?>
            
        </select>
    
        <div id="recargado"></div>
        <script language="javascript">
    
    function recargar(){    
       /// Aqui podemos enviarle alguna variable a nuestro script PHP
       //document.write(select);
        var variable_post= document.getElementById("opciones").value;;
       /// Invocamos a nuestro script PHP
        $.post("<?php echo $file;?>", {variable:variable_post}, function(data){
       /// Ponemos la respuesta de nuestro script en el DIV recargado
        $("#recargado").html(data);
    });         
    }
    </script>
        
        <?php
    } 
     
      
    function DrawSelectDependence(){
        ?>
        
        <p align="left">
        <select style="width: 400px" size="1" name="select" onclick="javascript:recargar();" id="opciones">
	       <option value="1">Operadores</option>
	       <option value="2">Guías</option>
	       <option value="3">Restaurante</option>
           <option value="4">Transporte</option> 
           <option value="5">Extensiones</option>
        <?php 
        



        ?>
            
        </select>
    
        <div id="recargado"></div>
        <script language="javascript">
    
    function recargar(){    
       /// Aqui podemos enviarle alguna variable a nuestro script PHP
       //document.write(select);
        var variable_post= document.getElementById("opciones").value;;
       /// Invocamos a nuestro script PHP
        $.post("prueba.php", {variable:variable_post}, function(data){
       /// Ponemos la respuesta de nuestro script en el DIV recargado
        $("#recargado").html(data);
    });         
    }
    </script>
        
        <?php
    }
    
    function DateFromTo($title,$boundary){
        
    ?>        
    <script>
    $(function() {

 
       $.datepicker.setDefaults($.datepicker.regional['es']); 
      
    
    });
    
	$(function() {
	   
 
  		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "-2m",
			changeMonth: true,
			changeYear: true,
			numberOfMonths: 4,
			onSelect: function( selectedDate ) {
			    
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		
        });

    });
	</script>
 
    <label for="from"><?php echo $boundary[0]?></label></br>
    <input type="text" class=":required"  id="from" name="from" /></br>
    <label for="from"><?php echo $boundary[1]?></label></br>
    <input type="text" class=":required" id="to" name="to"/>

    <?php
       
    // <label> <?php echo $title </label><br/><br/>    
    
    }
    
     function DateFromToFill($title,$boundary,$f,$t){
        
    ?>        
    <script>
    $(function() {

 
       $.datepicker.setDefaults($.datepicker.regional['es']); 
    
    });
    
	$(function() {
	   
 
  		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true    ,
			numberOfMonths: 3,
			onSelect: function( selectedDate ) {
			    
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		
        });
        
        
	});
	</script>
 
    <label for="from"><?php echo $boundary[0]?></label></br>
    <input type="text" value="<?php echo $f;?>" class=":required" id="from" name="from"  /></br>
    <label for="from"><?php echo $boundary[1]?></label></br>
    <input type="text" value="<?php echo $f;?>" class=":required" id="to" name="to"/>

    <?php
       
    // <label> <?php echo $title </label><br/><br/>    
    
    }
    
    
    function amysql($fecha){     
        
        $dia = substr($fecha,0,2);
        $mes   = substr($fecha,3,2);
        $ano = substr($fecha,6,4);

        $fecha = $ano . '-' . $mes . '-' . $dia; 

        return $fecha;
    }
    
     function aphp ($fecha){     
        //2011-12-31
        
        $ano = substr($fecha,0,4);
        $mes   = substr($fecha,5,2);
        $dia = substr($fecha,8,2);

        $fecha = $dia . '/' . $mes . '/' . $ano; 

        return $fecha;
    }
    
    function readOnly ($table, $nameid){
        
        $query = "SELECT $nameid FROM $table ORDER BY $nameid DESC LIMIT 1"; 
        $table = CModelo::getInstance()->getData($query);
        
        foreach($table as $row =>$colum){
        $table2 =$colum;
        foreach($table2 as $campo=>$valor){
           $id = $valor;}
           }
           
           $id = $id + 1;
           
          echo  "<label>Código </br><input type='text' name='$nameid' readonly = 'readonly' value='$id'></label></br>";
       
  
       }
                        
    
    
      function DrawHideSectionBeg(){
        ?>
       
        <style type="text/css"> 
        div.panel,p.flip
        {margin:12px;padding:5px;text-align:center;background:#bbdaf7;border:solid 2px #a3a3a3;
        }
        div.panel
        {height: auto;display:none;}
        </style>
        <div class="panel">    
        <?php
    }
    
      function DrawHideSectionEnd($name){
        ?>
       
         </div>
        <p class="flip"> <?php echo $name;?></p>
        <?php    
        
    }
    
    
    
       
      function DrawHideSectionIBeg(){
        ?>
       
        <style type="text/css"> 
        div.ipanel,p.iflip
        {margin:12px;padding:5px;text-align:center;background:#bbdaf7;border:solid 2px #a3a3a3;
        }
        div.ipanel
        {height: auto;display:none;}
        </style>
        <div class="ipanel">    
        <?php
    }
    
      function DrawHideSectionIEnd($name){
        ?>
       
         </div>
        <p class="iflip"> <?php echo $name;?></p>
        <?php    
        
    }
    
    
    
    function  DrawHead($action,$name,$method,$NAME){echo "<div id='register-box'>\n";echo "<form action='$action' method='$method' name='$name'>\n";echo "<h2>$NAME</h2>\n";}
    
    
    
    function  DrawHeadAjax($action,$method,$NAME){echo "<div id='register-box'>\n";echo "<form id='myForm' name='$NAME' action='$action' method='$method'>\n";echo "<h2>$NAME</h2>\n";}
        
    function  DrawHeadAjax2($action,$method,$NAME){echo "<div id='register-box'>\n";echo "<form id='myForm2' name='$NAME' action='$action' method='$method'>\n";echo "<h2>$NAME</h2>\n";}
   
       
    function DrawDivAjax(){
        
        ?>
        <div id="ajax_loader"><img id="loader_gif" src="<?php echo CConfig::getInstance()->rutalogica."/MDTour/ReloadPages";?>/js/loader.gif" style=" display:none;"/></div>
        <?php
    }
    //<form id="myForm" action="contacto.php" method="post" style="height:200px;">
    
    function  DrawFoot(){
        echo "</form>";
        echo "</div>";}
    function  DrawTextBox($items,$val_extensiones)
    {
        
        ?>
               
               <?php
                    $i = 0;
                    foreach($items as $id => $valor)
                    {
                        echo "<label>".$valor."</br><input type='text' name='$id' class='$val_extensiones[$i]'>"."</label></br >";
                        $i = $i+1;
                    }
               
               ?>
               
           
        <?php
        
    }
    
    function  DrawTextBoxArea($items,$val_extensiones)
    {
        //<textarea cols="2" rows="6" wrap="VIRTUAL" name="id"></textarea>
        ?>
               
               <?php
                    $i = 0;
                    foreach($items as $id => $valor)
                    {
                        echo "<label>".$valor."</br><textarea cols='37' rows='6' name='$id' class='$val_extensiones[$i]'></textarea>"."</label></br >";
                        $i = $i+1;
                    }
               
               ?>
               
           
        <?php
        
    }
    
    
    function DrawReadOnly($nameid,$label,$value){
          
          echo  "<label>$label </br><input type='text' name='$nameid' readonly = 'readonly' value='$value'></label></br>";
       
        
    }
    
    function DrawSelectPackages ($table,$campos,$NAME, $id)//especificar los campos que deben de aparecer 
    {
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table. " where idPack>$id";
        
        $table2=CModelo::getInstance()->getData($query);
        
        
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?>
       
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo].",";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
             
        </label>
        
    
    <?php
    }

    function DrawSelect($table,$campos,$NAME, $id)//especificar los campos que deben de aparecer 
    {
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;
                  
        
        $table2=CModelo::getInstance()->getData($query);
       
       
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?></br>
        <select style="width: 400px" name="<?php echo $id;?>" class=":required" id="<?php echo $id;?>"><option value=""></option>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select></br>       
        </label>
        
    
    <?php
    }
    
    function DrawSelectFilter($table,$campos,$NAME, $id, $filter)//especificar los campos que deben de aparecer 
    {
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table. $filter;
        // echo $query;         
        
        $table2=CModelo::getInstance()->getData($query);
       
       
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?></br>
        <select style="width: 400px" name="<?php echo $id;?>" class=":required" id="<?php echo $id;?>"><option></option>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select></br>       
        </label>
        
    
    <?php
    }
    
    
    function DrawSelectNo($table,$campos,$NAME, $id)//especificar los campos que deben de aparecer 
    {
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;
                  
        
        $table2=CModelo::getInstance()->getData($query);
       
       
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?></br>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </br>       
        </label>
        
    
    <?php
    }
    
    function DrawSelectNon($table,$campos,$NAME, $id)//especificar los campos que deben de aparecer 
    {
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;
                  
        
        $table2=CModelo::getInstance()->getData($query);
       
       
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?></br>
        <select name="<?php echo $id;?>" id="<?php echo $id;?>"><option value=""></option>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select></br>       
        </label>
        
    
    <?php
    }
    
    
    
    
     function getAnyId($maintable,$mainfield,$mainid,$subfield){
        
        $query="select ". $subfield ." from ". $maintable . " where $mainfield= $mainid";
        $table=CModelo::getInstance()->getData($query);
        
        
         foreach($table as $fila=>$columna){
            $tabla1=$columna;
                foreach($tabla1 as $field=>$value)
                {
                $identificador=$value;
            }
         }
         return $identificador;
     
    }
    
    function getDefaultTour($maintable,$mainfield,$mainid,$subfield){
        
        $query="select ". $subfield ." from ". $maintable . " where $mainfield= $mainid AND DefaultTourPack=1";
        $table=CModelo::getInstance()->getData($query);
        
        
         foreach($table as $fila=>$columna){
            $tabla1=$columna;
                foreach($tabla1 as $field=>$value)
                {
                $identificador=$value;
            }
         }
         return $identificador;
     
    }
    
  function DrawButton($nombre,$url){
//      
        echo "<input type=button onClick=\"parent.location='$url'\" value='$nombre'><br/>";
        }


    function DrawRadioButton($items,$name)
    {
      
      echo "<p >";
      
      foreach($items as $id => $valor)
                    {
                        echo "<label>".$id."<input type='radio' class=\"input-radio\" name='$name' value='$valor'>"."</label>\n";
                        
                    }
      
      
      echo "</p>";
      
        
        
    }
    
    function HiddenValue($hidden){
        echo "<input type='hidden' name='idHidden' value='$hidden'>"; 
    }
    
    function DrawSubmmit($nombre){echo "<p align='right'><input class='submit_button' type='submit' onclick='eliminar()' name=$nombre value='$nombre'></p>";}
   
    public static function getInstance()
        {
                //echo "<div id=register-box>";
        if(self::$instance==null)
                  self::$instance=new CDrawPageReg();
        //   echo "</div>";       
                return  self::$instance;
           
    
    }   
    
    
}

?>